package org.smile.db.result.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.smile.beans.converter.ConvertException;
import org.smile.beans.converter.TypeConverter;
import org.smile.beans.converter.type.BooleanConverter;
import org.smile.db.result.ColumnHandler;

public class BooleanColumnHandler implements ColumnHandler<Boolean> {
	static TypeConverter booleanConverter= BooleanConverter.getInstance();
	@Override
	public Boolean getColumn(ResultSet rs, int index) throws SQLException {
		Object res= rs.getObject(index);
		try {
			return (Boolean) booleanConverter.convert(res);
		} catch (ConvertException e) {
			throw new SQLException(e);
		}
	}

	@Override
	public void setColumn(PreparedStatement ps, int index,Boolean value) throws SQLException {
		ps.setBoolean(index, value);
	}

	@Override
	public Boolean getColumn(ResultSet rs, String column) throws SQLException {
		Object res= rs.getObject(column);
		try {
			return (Boolean) booleanConverter.convert(res);
		} catch (ConvertException e) {
			throw new SQLException(e);
		}
	}

}
